import 'package:flutter/material.dart';
import 'package:sui_shou_pai/module/effect.dart';

import '../data/announcement_list_item_data.dart';
import 'announcement_detail.dart';

Widget initAnnouncementListItem(
    BuildContext context, AnnouncementListItemData item) {
  return GestureDetector(
    onTap: () {
      Navigator.push(
          context,
          MaterialPageRoute(
              builder: (context) => AnnouncementDetail(item: item)));
    },
    child: Container(
      margin: EdgeInsets.fromLTRB(12, 12, 12, 0),
      padding: EdgeInsets.all(12),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: borderRadiusAll8(),
        boxShadow: [shadowOffsetY2()],
      ),
      child: Row(
        children: <Widget>[
          initAnnouncementText(
              item.title, item.importantLevel, item.time, item.publisher),
        ],
      ),
    ),
  );
}

Widget initAnnouncementText(
    String title, String importantLevel, String time, String publisher) {
  return Expanded(
      child: Container(
    height: 60,
    child: Column(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Row(
          children: [
            initAnnouncementImportantLevel(importantLevel),
            initAnnouncementTitle(title),
          ],
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            initAnnouncementTimePublisher(time, publisher),
          ],
        )
      ],
    ),
  ));
}

Widget initAnnouncementImportantLevel(String importantLevel) {
  return Container(
    margin: EdgeInsets.only(right: 8),
    padding: EdgeInsets.fromLTRB(6, 2, 6, 2),
    decoration: BoxDecoration(
      color: importantLevel == '紧急'
          ? Colors.red
          : importantLevel == '优先'
              ? Colors.blue
              : Colors.green,
      borderRadius: borderRadiusAll4(),
    ),
    child: Text(
      importantLevel,
      style: TextStyle(
        fontSize: 14,
        color: Colors.white,
      ),
    ),
  );
}

Widget initAnnouncementTitle(String title) {
  return Text(
    title,
    maxLines: 1,
    overflow: TextOverflow.ellipsis,
    style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
  );
}

Widget initAnnouncementTimePublisher(String time, String publisher) {
  return Text(
    '$time  $publisher',
    style: TextStyle(fontSize: 14, color: Colors.grey),
  );
}

Widget initAnnouncementComment(int commentCount) {
  return Row(
    children: [
      Icon(Icons.chat_bubble_outline, size: 16, color: Colors.grey),
      Text(
        ' ${commentCount.toString()} ',
        style: TextStyle(fontSize: 14, color: Colors.grey),
      ),
    ],
  );
}
